package com.shop.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.shop.entity.Order;
import com.shop.model.vo.Rsp;
import com.shop.service.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * (Order)表控制层
 *
 * @author makejava
 * @since 2020-11-21 12:10:58
 */
@Validated
@RestController
@AllArgsConstructor
public class OrderController {
    /**
     * 服务对象1
     */
    private final OrderService orderService;

    @PostMapping("placeOrder")
    public Rsp placeOrder(@RequestBody Order order, @RequestHeader("userId") Integer userId) {
        return orderService.placeOrder(order, userId);
    }

    @GetMapping("getOrderList")
    public Rsp getOrderList(String status, @RequestHeader("userId") Integer userId) {
        return orderService.getOrderList(userId, status);
    }

    @GetMapping("getOrderById")
    public Rsp getOrderById(Integer orderId) {
        return orderService.getOrderById(orderId);
    }

    @GetMapping("orderCount")
    public Rsp orderCount(@RequestHeader("userId") Integer userId) {
        return orderService.orderCount(userId);
    }

    @GetMapping("confirmOrder")
    public Rsp confirmOrder(Double distance, Integer merchantId, @RequestHeader("userId") Integer userId) throws JsonProcessingException {
        return orderService.getItemByMerchantId(distance, merchantId, userId);
    }

    @GetMapping("payOrder")
    public Rsp payOrder(Integer id, @RequestHeader("userId") Integer userId) throws JsonProcessingException {
        return orderService.payOrder(id, userId);
    }
}
